﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.BOM;
using FriendStar.Domain.IRepository.BOM;
using FriendStar.Repository.BOM;

namespace FriendStar.Application.BOM
{
    /// <summary>
	/// 数据视图 V_Mol_11_DA_Mold 对应的数据应用功能类。
	/// </summary>
	public class V_Mol_11_DA_MoldApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");  

        private IV_Mol_11_DA_MoldRepository service = new V_Mol_11_DA_MoldRepository();

        public List<V_Mol_11_DA_MoldEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<V_Mol_11_DA_MoldEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => (t.MoldNO.Contains(keyword) || t.MoldName.Contains(keyword)));
            }
            string extWhere = string.Empty;
            //if (!string.IsNullOrEmpty(keyword))
            //{
            //    if (!string.IsNullOrEmpty(extWhere))
            //    {
            //        extWhere += " AND ";
            //    }
            //    extWhere += string.Format("(MoldNO LIKE '%{0}%' or MoldName LIKE '%{0}%')", keyword);
            //}
            return service.FindList(expression, pagination, extWhere);
        }

        public List<V_Mol_11_DA_MoldEntity> GetList()
        {
            var expression = ExtLinq.True<V_Mol_11_DA_MoldEntity>();
            expression = expression.And(t => t.UseUnit == UseUnit);
            Pagination pagination = new Pagination();
            pagination.rows = int.MaxValue;
            pagination.sidx = "MoldNO";
            pagination.sord = "ASC";
            return service.FindList(expression, pagination);
        }

        public V_Mol_11_DA_MoldEntity GetItem(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }

            var expression = ExtLinq.True<V_Mol_11_DA_MoldEntity>();
            expression = expression.And(t => t.MoldNO == id);
            return service.FindEntity(expression);
        }

        public V_Mol_11_DA_MoldEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
    }
}